package cnpm02.j2ee.group3.model;

import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.NotNull;

@Entity
@Table(name = "TICKET", uniqueConstraints = @UniqueConstraint(columnNames = {
                "FlightId", "TicketTypeId"}))
@AttributeOverride(name = "id", column = @Column(name = "TicketId"))
public class Ticket extends AbstractEntity {
	private static final long serialVersionUID = 1L;

	@NotNull
	@ManyToOne(cascade = {PERSIST, MERGE})
	@JoinColumn(name = "FlightId", nullable = false)
	private Flight flight;
	
	@NotNull
	@ManyToOne(cascade = {PERSIST, MERGE})
	@JoinColumn(name = "TicketTypeId", nullable = false)
	private TicketType ticketType;
	
	@NotNull
	@Column(name = "Price", nullable = false)
	private long price;
	
	@NotNull
	@Column(name = "Quantity", nullable = false)
	private int quantity;
	
	@NotNull
	@Column(name = "SoldQuantity", nullable = false)
	private int soldQuantity;
	
	public Ticket() {
		super();
	}
	
	public Ticket(Flight flight, TicketType ticketType, long price, int quantity) {
		super();
		this.flight = flight;
		this.ticketType = ticketType;
		this.price = price;
		this.quantity = quantity;
		this.soldQuantity = 0;
	}
	
	public void setFlight(Flight flight) {
		this.flight = flight;
	}
	
	public Flight getFlight() {
		return flight;
	}

	public void setTicketType(TicketType ticketType) {
		this.ticketType = ticketType;
	}

	public TicketType getTicketType() {
		return ticketType;
	}

	public void setPrice(long price) {
		this.price = price;
	}

	public long getPrice() {
		return price;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public int getQuantity() {
		return quantity;
	}

	public void setSoldQuantity(int soldQuantity) {
		this.soldQuantity = soldQuantity;
	}

	public int getSoldQuantity() {
		return soldQuantity;
	}
}
